package org.dromara.study.controller;

import org.dromara.common.core.domain.R;
import org.dromara.study.domain.entity.Department;
import org.dromara.study.domain.vo.DepartmentTreeVo;
import org.dromara.study.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/department")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    @PostMapping("/add")
    public R<String> add(@RequestBody Department department) {
        departmentService.save(department);
        return R.ok("新增成功");
    }


    @GetMapping("/getTree")
    public R<List<DepartmentTreeVo>> getTree() {
        return R.ok(departmentService.getTree());
    }


    @PostMapping("/edit")
    public  R<String> edit(@RequestBody Department department){
        departmentService.updateById(department);
        return R.ok("编辑成功");
    }


    @GetMapping("/remove/{id}")
    public R<String> remove(@PathVariable("id") Long id){
        departmentService.removeById(id);
        return R.ok("删除成功");
    }

}
